import { Component, sys, _decorator } from 'cc';
import { OpenItems } from '../../../configs/Levels';
import GameConst from '../common/GameConst';
import Data from '../manager/Data';
import WindowManager from '../manager/WindowManager';
const { ccclass, property } = _decorator;
@ccclass('DebugTools')
export default class DebugTools extends Component {
    start() {
        this.addBtn("清除数据", () => {
            localStorage.setItem(GameConst.local_data_key, "");
        })

        this.addBtn("金币+100", () => {
            Data.user.coin += 100
        })

        this.addBtn("Star+100", () => {
            Data.user.star += 100

            if (Data.user.openIndex < OpenItems.length - 1) {
                //解锁新物品
                WindowManager.ins.open("NewPackOpenedLayer", Data.user.openIndex);
            }
        })

        this.addBtn("LV++", () => {
            Data.user.lv++
        })
    }

    addBtn(name: string, callback: Function) {
        let toolbar = document.getElementsByClassName("toolbar")[0];
        if (!toolbar) return;
        let div = document.createElement("div");
        div.className = "item";
        div.innerHTML = "<button id='" + name + "'>" + name + "</button>";
        toolbar.appendChild(div);

        document.getElementById(name).onclick = () => {
            callback()
        };
    }
}
